#pragma once
#include"const.h"
#include"Singleton.h"
#include"ConFigMgr.h"
#include<grpcpp/grpcpp.h>
#include"message.pb.h"
#include<atomic>
#include"message.grpc.pb.h"

using grpc::Channel;
using grpc::Status;
using grpc::ClientContext;

using message::GetChatServerReq;
using message::GetChatServerRsp;
using message::LoginReq;
using message::LoginRsp;
using message::StatusService;

class StatusConPool {
public:
	StatusConPool(size_t poolsize,string port,string host);
	~StatusConPool();
	std::unique_ptr<StatusService::Stub> GetConnection();
	void ReturnConnection(std::unique_ptr<StatusService::Stub> con);
	void Close();

private:
	std::atomic<bool> b_stop_;
	size_t poolsize_;
	string port_;
	string host_;
	std::queue<std::unique_ptr<StatusService::Stub>> connections_;
	std::condition_variable cond_;
	std::mutex mutex;
};

class StatusGrpcClient:public Singleton<StatusGrpcClient> {
	friend class Singleton<StatusGrpcClient>;
public:
	~StatusGrpcClient();
	GetChatServerRsp GetChatServer(int uid);

private:
	StatusGrpcClient();
	std::unique_ptr<StatusConPool> pool_;
};